﻿using UnityEngine;
using UnityEngine.EventSystems;

public class UpgradeButton : MonoBehaviour, IPointerClickHandler
{

    public void OnPointerClick(PointerEventData eventData)
    {
        SkillManager.Instance.UpgradeSkill();        
    }


    private void Start()
    {
        SkillManager.Instance.SkillSelectedEvent += OnSkillSelected;
    }

    // 当选中技能图标时触发
    public void OnSkillSelected(SkillData skillData)
    {
        ChangeButtonEnable(skillData);
    }


    void ChangeButtonEnable(SkillData skillData)
    {
        if(skillData == null)
        {
            SetButtonEnable(false);
            return;
        }
        if(skillData.isUnlocked && gameObject.activeSelf)
        {
            return;
        }
        if(skillData.CanUpgrade())
        {
            SetButtonEnable(true);
            return;
        }
        SetButtonEnable(false);
    }

    void SetButtonEnable(bool enable)
    {
        gameObject.SetActive(enable);
    }
}
